<%--
  Created by IntelliJ IDEA.
  User: zhangdeng
  Date: 2020/11/30
  Time: 23:45
  To change this template use File | Settings | File Templates.
--%>
<%@page import="com.sjsq.dao.impl.UserDaoImpl"%>
<%@page import="com.sjsq.dao.UserDao"%>
<%@page import="com.sjsq.po.User"%>
<%@ page import="com.sjsq.po.Book" %>
<%@ page import="com.sjsq.dao.BookDao" %>
<%@ page import="com.sjsq.dao.impl.BookDaoImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>处理新增图书</title>
    <style type="text/css">
        #before{
            text-align: center;
        }
        #head{
            background: #eeeeee;height: 80px;
        }
        #headLink{
            font-size: 20px;
        }
        #headWelLink{
            font-size: 20px;
        }
    </style>
</head>
<body>
<%--头部信息--%>
<%
    User user =(User)session.getAttribute("user");
    if(user == null){
        response.sendRedirect("login.jsp");
    }else {
%>
<div id="head">
    <table width="100%">
        <td id="headWelLink">欢迎您：<%=user.getName()%></td>
        <td align="right" id="headLink">
            <a href="logout.jsp">安全退出</a>
        </td>
    </table>
</div>
<%
    }
%>

<%
    // 设置获取注册时的编码为UTF-8
    request.setCharacterEncoding("UTF-8");
    Book book=new Book();
    //获取admin_addbook.jsp页面提交的账号和密码
    String bookname=request.getParameter("bookname");
    Double price= Double.parseDouble(request.getParameter("price"));
    String author=request.getParameter("author");
    String publish=request.getParameter("publish");

    //获取admin_addbook.jsp页面提交的账号和密码设置到实体类User中
    book.setBookname(bookname);
    book.setPrice(price);
    book.setAuthor(author);
    book.setPublish(publish);

    System.out.println("添加的图书信息");
    System.out.println(book);

    //引入数据交互层
    BookDao dao=new BookDaoImpl();
    boolean flag=dao.addBook(book);


    if(flag){
        response.sendRedirect("admin.jsp");
    }else{
        response.sendRedirect("error.jsp");
    }
%>
</body>
</html>
